import { LoginCenterApi } from './modules/LoginCenterApi';
import route from '@/uni_modules/uv-ui-tools/libs/util/route.js';
import store from '@/store';
let baseUrl = '';
let currentDomain = '';
// #ifdef H5
currentDomain = window.location.host;
// #endif

const getToken = () => {
  return new Promise((resolve, reject) => {
    console.log(uni.getStorageSync('share_id'), '----------5555555');

    // #ifdef MP-WEIXIN
    uni.login({
      provider: 'weixin',
      success: (res1) => {
        console.log(res1);
        LoginCenterApi.login({
          jsCode: res1.code,
          share_id: store.state.share_id,
        }).then((res) => {
          uni.setStorageSync('token', res.data);
          store.commit('setShareId', ' ');
          uni.showLoading({
            title: '加载中',
          });
          // // 获取当前也页面
          // setTimeout(() => {
          //   let page = getCurrentPages().pop();
          //   page.onShow();
            uni.hideLoading();
          // }, 1000);
          resolve(res.data); // 临时路径
        });
      }, 
    });
    // #endif
    // #ifdef H5
    console.log(currentDomain, 'currentDomain');
    window.location.href =
      'https://www.yirenyian.com/user/login?target=' +
      encodeURIComponent('http://' + currentDomain + '/index.html');
    resolve(currentDomain);

    // #endif
  });
};
// #ifdef MP-WEIXIN
const accountInfo = uni.getAccountInfoSync();
var envVersion = accountInfo.miniProgram.envVersion;
console.log(envVersion, 'envVersionenvVersion');
// baseUrl = 'https://api81.vrupup.com/tp/1407/public/index.php/api/'; //正式环境
baseUrl = 'https://api81.vrupup.com/tp/1407_test/public/index.php/api/'; //测试环境
// console.log(
//   `\n %c 体验版 and 开发版 \n\n`,
//   'color: #ffffff; background: #e82702; padding:5px 0; border-radius: 5px;'
// );
// if (envVersion == 'develop' || envVersion == 'trial') {
//   baseUrl = 'https://api81.vrupup.com/tp/1407/public/index.php/api/';
//   console.log(
//     `\n %c 体验版 and 开发版 \n\n`,
//     'color: #ffffff; background: #e82702; padding:5px 0; border-radius: 5px;'
//   );
// } else if (envVersion == 'release') {
//   baseUrl = 'https://java.vrupup.com/medical-care/api/';
//   console.log(
//     `\n %c 正式版 \n\n`,
//     'color: #ffffff; background: #15d36a; padding:5px 0; border-radius: 5px;'
//   );
// } else {
//   console.error('判断出错了', envVersion);
// }
// switch (envVersion) {
//   case 'develop' || 'trial': //体验版 and 开发版
//     break;
//   case 'release': //正式版
//     baseUrl = 'https://java.vrupup.com/medical-care/api/';
//     console.log(
//       `\n %c 正式版 \n\n`,
//       'color: #ffffff; background: #15d36a; padding:5px 0; border-radius: 5px;'
//     );
//     break;
//   default:
//     console.error('判断出错了', envVersion);
//     break;
// }
// #endif
// #ifdef H5
if (process.env.NODE_ENV === 'development') {
  console.log('开发环境');
  baseUrl = 'https://api81.vrupup.com/tp/1407/public/index.php/api/';

  console.log(
    `\n %c 开发环境 \n\n`,
    'color: #ffffff; background: #e82702; padding:5px 0; border-radius: 5px;'
  );
} else {
  console.log('生产环境');
  baseUrl = 'https://api81.vrupup.com/tp/1407/public/index.php/api/';

  console.log(
    `\n %c 生产环境 \n\n`,
    'color: #ffffff; background: #15d36a; padding:5px 0; border-radius: 5px;'
  );
}
// #endif

export {
  baseUrl,
  getToken,
  // #ifdef H5
  currentDomain,
  // #endif
};
